import { AGraph, VNode, ArcNode } from "./Graph.type";

function visit(g: AGraph, node: ArcNode) {
	let VNodes = g.adjlist[node.adjvex]
	console.log(VNodes.data, "/ ");
}

function BFS(g: AGraph, v: VNode) {
	let markArr: Array<number>; //</number>
	let queue: Array<ArcNode>; //</VNode>
	markArr = new Array(g.n);
	let i = 0;
	let temp: ArcNode;
	queue.push(v.firstArc);
	while (queue.length !== 0 && markArr[i] == 0) {
		temp = queue.shift();
		visit(g, temp);
		markArr[temp.adjvex] = 1;
		while ((temp = temp.nextarc) !== null) {
			if (markArr[temp.adjvex] == 0) {
				queue.push(temp);
			}
		}
	}
}

function DFS(g: AGraph, v: ArcNode) {
	let markArr: Array<number>; //</number>
	markArr = new Array(g.n);

	function _DFS(g: AGraph, v: ArcNode) {
		visit(g, v);
		markArr[v.adjvex] = 1;
		while (v.nextarc != null) {
			v = v.nextarc;
			if (markArr[v.adjvex] == 0)
				_DFS(g, g.adjlist[v.adjvex].firstArc);
		}
	}
}
